/**
 * Created by 陈奇 on 14-11-15.
 */
var express = require('express');
var router = express.Router();
var db = require('./conn'); //先引入数据库链接
router.get('/', function(req, resIndex) {
    db.pool.getConnection(function(err, connection) {
        var sql = 'select * from bookinfo order by bookid+0';
        connection.query(sql, function(error, res) {
            var name = []; //书名
            var prize = []; //书的价格
            var imgurl = []; //图片路径
            if (res.length != 0) {
                for (var i in res) {
                    name.push(res[i].name);
                    prize.push(res[i].prize);
                    imgurl.push(res[i].imgurl);
                }
            }
            resIndex.render('index', {
                title: "从这里开始",
                bookname: name,
                prize: prize,
                imgurl: imgurl
            });
        });
        connection.release();
    });
});

module.exports = router;